package org.example.dao;

import org.apache.ibatis.annotations.*;
import org.example.entity.Admin;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface AdminDao{

  List<Admin> getAll();

  //Admin findByUsername(String userName);
  @Select("select * from `admin` where `userName` = #{userName}")
  Admin findByUsername(@Param("userName") String userName);

  @Select("select * from `admin` where `id` = #{id}")
  Admin findById(@Param("id")Integer id);

  @Select("select * from `admin` where `userName` = #{userName}")
  Admin findByName(@Param("userName") String userName);

  @Insert("INSERT INTO `admin` (userName,gender,age,phone) VALUES(#{userName},#{gender},#{age},#{phone})")
  int insertSelective(Admin admin);

  @Delete("DELETE FROM `admin` WHERE id = #{id}")
  void deleteByPrimaryKey(Integer id);

  @Update("UPDATE `admin` SET userName='#{userName}', gender=#{gender}, age=#{age}, phone=#{phone} WHERE id=#{id}")
  void updateByPrimaryKeySelective(Admin admin);

  List<Admin> findBySearch(@Param("search") Admin search);
}
